package com.demo.pojo;


import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author leiliang
 * @version 1.0
 * @Description
 * @date 2021/6/1 17:15
 */
public class TestTree {
    public static void main(String[] args) {

/*
        SsopDict ssopDict = new SsopDict();

        ssopDict.setId(2001);
        ssopDict.setCode("administrative_divisions");
        ssopDict.setLabel("行政区域");
        List<SsopDictValue> ssopDictValues = new ArrayList<>();
        SsopDictValue ssopDictValue = new SsopDictValue();

        ssopDictValue.setId(200049L);
        ssopDictValue.setDictId(2001L);
        ssopDictValue.setParentId(0L);
        ssopDictValue.setLabel("中国");
        ssopDictValue.setCode("CN");
        //建一个最大的 SsopDictValue
        List<SsopDictValue> ssopChilderens = new ArrayList<>();
        SsopDictValue children = new SsopDictValue();

        children.setId(200250L);
        children.setDictId(2001L);
        children.setParentId(200049L);
        children.setLabel("北京市");
        children.setCode("110000");
        ssopChilderens.add(children);

        //建第二个list  放到第一个new的对象里
        List<SsopDictValue> ssopChilderens1 = new ArrayList<>();
        SsopDictValue children1 = new SsopDictValue();

        children1.setId(200251L);
        children1.setDictId(2001L);
        children1.setParentId(200250L);
        children1.setLabel("市辖区");
        children1.setCode("110100");
        ssopChilderens1.add(children1);
        children.setChildren(ssopChilderens1);

        List<SsopDictValue> ssopChilderens2 = new ArrayList<>();

        SsopDictValue children2 = new SsopDictValue();

        children2.setId(200252L);
        children2.setDictId(2001L);
        children2.setParentId(200251L);
        children2.setLabel("东城区");
        children2.setCode("110101");
        ssopChilderens2.add(children2);
        children1.setChildren(ssopChilderens2);


        ssopDictValue.setChildren(ssopChilderens);
        ssopDictValues.add(ssopDictValue);

        ssopDict.setValues(ssopDictValues);
        System.out.println("组装的数据结构" + JSONObject.toJSONString(ssopDict));
*/


        List<Zone> zoneList = new ArrayList<>();
        zoneList.add(new Zone("1", "中国", "0", "1"));
        zoneList.add(new Zone("2", "北京市", "1", "1"));
        zoneList.add(new Zone("3", "市辖区", "2", "2"));
        zoneList.add(new Zone("31", "东城区", "3", "3"));
        zoneList.add(new Zone("32", "西城区", "3", "2"));
        zoneList.add(new Zone("33", "昌平区", "3", "2"));
        zoneList.add(new Zone("44", "河北省", "1", "2"));
        zoneList.add(new Zone("45", "石家庄市", "44", "2"));
        zoneList.add(new Zone("47", "长安区", "45", "2"));
        zoneList.add(new Zone("48", "裕华区", "3", "2"));
        zoneList.add(new Zone("49", "新华区", "3", "2"));
        zoneList.add(new Zone("88", "美国", "0", "10"));
        zoneList.add(new Zone("99", "英国", "0", "11"));
        zoneList.add(new Zone("00", "日本", "0", "12"));

        //List<Zone> rootZone1 = ZoneUtils.buildTree1(zoneList); // 测试第一种方法
        //List<Zone> rootZone2 = ZoneUtils.buildTree2(zoneList); // 测试第二种方法

        List<Zone> rootZone3 = ZoneUtils.buildTree3(zoneList); // 测试第三种方法
        List<Zone> collect = rootZone3.stream().sorted(Comparator.comparing(Zone::getOrderBy)).filter(v -> v.parentId.equals("0")).collect(Collectors.toList());
      }

}
